Imports DAL
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Configuration
Imports MyClasses 'Pankaj
'<Assembly >
'Class is used To Search  For All.
'Except Grid & Search For Combo , all the Controls are Created at Run Time
'As per Search for,related Controls get Visible true with regarding Values from database
'comparision operators are also take from db
'
'</Assembly>
Public Class frmMasterBrowse
    '---------------------------------VARIABLES --------------------------------------------------------'
    Private intArraySize As Integer = 10            'Max 10 Criteria are used for Search
    Private cmDItemArr(intArraySize - 1) As ComboBox     'For dDItems in where clause in search query
    Private cmbOperArr(intArraySize - 1) As ComboBox     'For operators in where clause in search query
    Private dtDItemArr(intArraySize - 1) As DataTable    'Datatable as datasource for each Itemcombo
    Private dtbOperArr(intArraySize - 1) As DataTable    'Datatable as datasource for each operatorcombo
    Private txtValue(intArraySize - 1) As TextBox        'Textboxes to enter values for items in  where clause
    Private txtValueTo(intArraySize - 1) As TextBox      'if Second value 
    Private lblTo(intArraySize - 1) As Label             'For To Label    
    Private dtbMsearch As DataTable                  'Stores The Items can be Search 
    Private dtDItemsToShow As DataTable              'Stores The Fields to Show in Grid  
    Private _Flag As Boolean                         'Temporary adjustment for cmDSearchcombo(it calls selectedindex changed at loading data to avoid that)
    Private intVspace As Integer = 8, intHspace As Integer = 8 'intVspace Vertical spacing Bet two controls  & intHspace Horizontal spacing Bet two controls
    Private strSql As String                         'Stores the Select Query   
    Private intRecords As Integer
    Public strRecordNo As String = 0               'Used to Return the Selected Record
    Public strSearch As String

    Dim tableFont, titlefont, headfont, tabletitlefont As Font
    Dim X1, X2, X3 As Integer
    Dim wi As Integer = 0
    Dim PHi As Double
    Dim Y As Integer
    Dim intPrintNext As Integer = 1
    Dim pageWidth As Integer
    Dim dobTotal As Double
    Dim curY As Integer
    Dim Foot1 As String
    Dim Foot2 As String
    Dim Foot3 As String
    Dim ClsComman As New CCommon
    Dim PageNo As Integer = 1

    '---------------------------------Something EXTRA --------------------------------------------------------'
    'keycode 222 is for SingleQuote which is not allowed in Query values so removed from all value textboxes
    '---------------------------------CODE --------------------------------------------------------'

    Public Sub New(ByVal Search As String)
        strSearch = Search
        InitializeComponent()
    End Sub

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub frmMasterBrowse_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        'Rauhl_ITS@20073012 : Add following code display help
        'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Master Browse")
        e.Cancel = True
    End Sub

    Private Sub frmMasterBrowse_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.F1 Then
            'Rauhl_ITS@20073012 : Add following code display help
            'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Master Browse")
        End If
    End Sub

    ' ---------------------------------FORM & CONTROL EVENTS --------------------------------------------------------'
    Private Sub frmBrowseEmp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            If strSearch Is Nothing Then
                btnOk.Enabled = False
            Else
                cmDSearch.Enabled = False
            End If
            Call CreateControls()
            Call DisplayData()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "frmBrowseEmp_Load")
            Me.Cursor = Cursors.Default
        End Try
        Call SetGridColor()
    End Sub

    Private Sub cmDSearch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmDSearch.SelectedIndexChanged
        If _Flag = False Then Exit Sub
        Me.Cursor = Cursors.WaitCursor
        Load_Data()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Me.Cursor = Cursors.WaitCursor
        Call Display_Results()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        strRecordNo = "0"
        Me.Close()
    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Try
            If strSearch Is Nothing Then Exit Sub
            If (fgResults.Rows.Count - 1) <= 0 Then
                BCommon.ShowMsgError(10082)
                Me.Close()
                Exit Sub
            End If
            If fgResults.RowSel = 0 Then
                BCommon.ShowMsgError(10291)
                Exit Sub
            End If
            If fgResults.Item(fgResults.RowSel, 1) Is Nothing Then
                BCommon.ShowMsgError(10291)
            Else
                If fgResults.Item(fgResults.RowSel, 1).ToString() = "" Then
                    strRecordNo = "0"
                Else
                    strRecordNo = fgResults.Item(fgResults.RowSel, 1)
                End If
                Me.Close()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnOk_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub dtPicker_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtPicker.CloseUp
        CType(dtPicker.Tag, TextBox).Text = Format(CDate(dtPicker.Value), "dd/MM/yy")
        dtPicker.Visible = False
    End Sub

    Private Sub dtPicker_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtPicker.KeyUp
        Try
            If e.KeyCode = Keys.Enter Then
                CType(dtPicker.Tag, TextBox).Text = Format(CDate(dtPicker.Value), "dd/MM/yy")
                dtPicker.Visible = False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "dtPicker_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub dtPicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtPicker.ValueChanged
        Try
            CType(dtPicker.Tag, TextBox).Text = Format(CDate(dtPicker.Value), "dd/MM/yy")
            dtPicker.Visible = False
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "dtPicker_ValueChanged")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            If cmDSearch.SelectedValue = 14 Then
                If fgResults.RowSel = 0 Then
                    BCommon.ShowMsgError(10267)
                Else
                    ClsComman.BillID = fgResults.Item(fgResults.RowSel, 2)
                    ClsComman.SaleID = fgResults.Item(fgResults.RowSel, 1)
                    PrintFinalBIll()
                End If
            Else
                If fgResults.Item(1, 2) <> "" Then
                    Dim pd As Printing.PrintDocument
                    pd = fgResults.PrintParameters.PrintDocument()
                    With pd.DefaultPageSettings
                        .Landscape = True
                        .Margins.Left = 150
                    End With
                    'Divya @ 14/03/2008
                    fgResults.PrintParameters.PrintPreviewDialog.ShowIcon = True
                    'fgResults.PrintParameters.PrintPreviewDialog.Icon = Global.Pharmacy.My.Resources.RxOffice1Icon32x32
                    '>>End
                    fgResults.PrintGrid("VB Tutorial", C1.Win.C1FlexGrid.PrintGridFlags.FitToPageWidth + C1.Win.C1FlexGrid.PrintGridFlags.ShowPreviewDialog)
                    'Me.PrintPreviewDialog1.Icon = Global.Pharmacy.My.Resources.RxOffice1Icon32x32
                Else
                    BCommon.ShowMsgError(10288)
                End If
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "BtnPrint_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ' --------------------------------- PROCEDURES   --------------------------------------------------------'
    Private Sub DisplayData()
        'fills Search Combo and loads data
        Dim count As Integer
        Dim dtbSource As DataTable
        Try
            'Rahul_ITS@14/12/2007 : Replace AssignLabels Call with SetFormStandards
            'Call BCommon.AssignLabels(Me) 'Vrushali    27/07/2007
            Call BCommon.SetFormStandards(Me, False)
            Call BCommon.SetDatePickerMaxMinDate(dtPicker)
            BCommon.SetFlexGrid(fgResults)
            _Flag = False
            dtbMsearch = DSearch.GetMasetrSearchs()
            cmDSearch.DataSource = dtbMsearch
            cmDSearch.ValueMember = dtbMsearch.Columns(0).ToString()
            cmDSearch.DisplayMember = dtbMsearch.Columns(1).ToString()
            _Flag = True
            Load_Data()
            'To set an index fo cmDSearch to strSearch,for which search form is called.
            dtbSource = cmDSearch.DataSource.Copy()
            For count = 0 To dtbSource.Rows.Count - 1
                If dtbSource.Rows(count).Item(1) = strSearch Then cmDSearch.SelectedValue = dtbSource.Rows(count).Item(0) : Exit For
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "DisplayData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub CreateControls()
        'Search controls are created here
        Dim intX As Integer = 10  'Starting X position for ItemCombo
        Dim intY As Integer = 10 'Starting Y position for ItemCombo
        Dim Fnt As Font = New Font("Microsoft Sans Serif", 8)
        Dim ptcmbSize As Point = New Point(120, 15) 'Combo Box Size
        Dim intCount As Integer 'temp Counter
        Try
            For intCount = 0 To intArraySize - 1
                ' Items in Where Clause
                cmDItemArr(intCount) = New ComboBox()
                cmDItemArr(intCount).Visible = False
                cmDItemArr(intCount).Parent = grpbControls
                cmDItemArr(intCount).Size = ptcmbSize
                cmDItemArr(intCount).Location = New Point(intX, intY)
                cmDItemArr(intCount).Font = Fnt
                cmDItemArr(intCount).DropDownStyle = ComboBoxStyle.DropDownList

                'OperatorCombo for where Clause
                cmbOperArr(intCount) = New ComboBox()
                cmbOperArr(intCount).Visible = False
                cmbOperArr(intCount).Parent = grpbControls
                cmbOperArr(intCount).Size = New Point(ptcmbSize.X / 2, ptcmbSize.Y)
                cmbOperArr(intCount).Location = New Point(intX + cmDItemArr(intCount).Size.Width + intHspace, intY)
                cmbOperArr(intCount).Font = Fnt
                cmbOperArr(intCount).DropDownStyle = ComboBoxStyle.DropDownList

                'TextBox for Values where Clause00
                txtValue(intCount) = New TextBox()
                txtValue(intCount).Visible = False
                txtValue(intCount).Parent = grpbControls
                txtValue(intCount).Size = New Point(ptcmbSize.X * 2 / 3, ptcmbSize.Y)
                txtValue(intCount).Location = New Point(cmbOperArr(intCount).Location.X + cmbOperArr(intCount).Size.Width + intHspace, intY)
                txtValue(intCount).Font = Fnt

                'Label for To Value
                lblTo(intCount) = New Label()
                lblTo(intCount).Visible = False
                lblTo(intCount).Parent = grpbControls
                lblTo(intCount).AutoSize = True
                lblTo(intCount).Text = "To"
                lblTo(intCount).Location = New Point(txtValue(intCount).Location.X + txtValue(intCount).Size.Width + intHspace, intY)
                lblTo(intCount).Font = Fnt

                'TextBox for Values where Clause
                txtValueTo(intCount) = New TextBox()
                txtValueTo(intCount).Visible = False
                txtValueTo(intCount).Parent = grpbControls
                txtValueTo(intCount).Size = New Point(ptcmbSize.X * 2 / 3, ptcmbSize.Y)
                txtValueTo(intCount).Location = New Point(lblTo(intCount).Location.X + lblTo(intCount).Size.Width + intHspace, intY)
                txtValueTo(intCount).Font = Fnt
                intY = intY + 20 + intVspace
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "CreateControls")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub ClearValueControls()
        'To set blank in search values textboxes
        Try
            Dim intCount As Integer 'temp Counter
            For intCount = 0 To intArraySize - 1
                txtValue(intCount).Text = ""
                txtValueTo(intCount).Text = ""
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearValueControls")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub HideValueControls()
        'By Default all value controls(in which values for search are entered
        Dim intCount As Integer
        Try
            For intCount = 0 To intArraySize - 1
                txtValue(intCount).Visible = False
                lblTo(intCount).Visible = False
                txtValueTo(intCount).Visible = False
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "HideValueControls")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub Load_Data()
        'Fills the Data in All the run time created controls from Database
        Try
            Call RemoveComboHandlers()
            Call RemoveAllValueHandlers()
            Call HideValueControls()

            Dim dtDSearchItems As DataTable = DSearch.GetSearchItems(cmDSearch.SelectedValue.ToString())
            Dim dtbOperators As DataTable = DSearch.GetOperators
            Dim dtbFromOperators As DataTable = DSearch.GetFromOperators
            Dim dtbAllOperators As DataTable = DSearch.GetAllOperators

            intRecords = dtDSearchItems.Rows.Count
            Dim intCount As Integer = 0

            For intCount = 0 To intRecords - 1
                If intCount >= intArraySize Then Exit For
                cmDItemArr(intCount).Visible = True
                cmbOperArr(intCount).Visible = True

                dtDItemArr(intCount) = dtDSearchItems.Copy
                cmDItemArr(intCount).DataSource = dtDItemArr(intCount)

                cmDItemArr(intCount).ValueMember = dtDItemArr(intCount).Columns(0).ToString()
                cmDItemArr(intCount).DisplayMember = dtDItemArr(intCount).Columns(1).ToString()
                cmDItemArr(intCount).SelectedValue = dtDSearchItems.Rows(intCount).Item(0)

                Select Case (CStr(dtDSearchItems.Rows(intCount).Item(2).ToString()))
                    Case "INT"
                        dtbOperArr(intCount) = dtbAllOperators.Copy
                        Call AddIntHandlers(intCount)
                    Case "DATETIME"
                        dtbOperArr(intCount) = dtbAllOperators.Copy
                        Call AddDateHandlers(intCount)
                    Case "STRING"
                        If CStr(dtDSearchItems.Rows(intCount).Item(3).ToString()) = "Y" Then
                            dtbOperArr(intCount) = dtbFromOperators.Copy
                        Else
                            dtbOperArr(intCount) = dtbOperators.Copy
                        End If

                        Call AddStringHandlers(intCount)
                    Case "CHAR"
                        dtbOperArr(intCount) = dtbOperators.Copy
                        Call AddCharHandlers(intCount)
                    Case "DOUBLE"
                        dtbOperArr(intCount) = dtbAllOperators.Copy
                        Call AddDoubleHandlers(intCount)
                    Case "IDSTRING"
                        If CStr(dtDSearchItems.Rows(intCount).Item(3).ToString()) = "Y" Then
                            dtbOperArr(intCount) = dtbFromOperators.Copy
                        Else
                            dtbOperArr(intCount) = dtbOperators.Copy
                        End If
                        Call AddStringHandlers(intCount)
                End Select
                cmbOperArr(intCount).DataSource = dtbOperArr(intCount)

                cmbOperArr(intCount).ValueMember = dtbOperArr(intCount).Columns(0).ToString()
                cmbOperArr(intCount).DisplayMember = dtbOperArr(intCount).Columns(1).ToString()
            Next

            For intCount = intRecords To intArraySize - 1
                cmDItemArr(intCount).Visible = False
                cmbOperArr(intCount).Visible = False
            Next

            dtDItemsToShow = DSearch.GetDisplayItems(cmDSearch.SelectedValue.ToString())
            cfgShowGroup.Rows.Count = dtDItemsToShow.Rows.Count + 1

            For intCount = 0 To dtDItemsToShow.Rows.Count - 1

                cfgShowGroup.Item(intCount + 1, 0) = "False"
                cfgShowGroup.Item(intCount + 1, 1) = "True"
                cfgShowGroup.Item(intCount + 1, 2) = dtDItemsToShow.Rows(intCount).Item(4).ToString()
            Next

            cfgShowGroup.Rows(1).Visible = False
            Call AddComboHandlers()
            Call ClearValueControls()
            'Display_Results()
            fgResults.DataSource = Nothing
            fgResults.Cols(1).Visible = False
            fgResults.Cols.Count = cfgShowGroup.Rows.Count
            For intCount = 1 To fgResults.Cols.Count - 1
                fgResults.Cols(intCount).Caption = cfgShowGroup.Rows(intCount).Item(2).ToString
            Next
            'FOR DISPLAY COLUMN

            For intCount = 2 To cfgShowGroup.Rows.Count - 1
                fgResults.Cols(intCount).Visible = CBool(cfgShowGroup.Item(intCount, 1))
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "Load_Data")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub Display_Results()
        Try
            If ValidateValues() = False Then Me.Cursor = Cursors.Default : Exit Sub
            Dim intCount As Integer
            strSql = "SELECT " & BuildSelectClause() & " " & FromClause() & " " & WhereClause() & " " & OrderClause()
            strSql = strSql.Replace("`", "'")
            fgResults.DataSource = DSearch.GetResults(strSql)
            fgResults.Cols(1).Visible = False

            For intCount = 1 To fgResults.Cols.Count - 1
                fgResults.Cols(intCount).Caption = cfgShowGroup.Rows(intCount).Item(2).ToString
            Next

            For intCount = 1 To fgResults.Rows.Count - 1
                fgResults.Rows(intCount).Item(0) = intCount
            Next
            'FOR DISPLAY COLUMN
            For intCount = 2 To cfgShowGroup.Rows.Count - 1
                fgResults.Cols(intCount).Visible = CBool(cfgShowGroup.Item(intCount, 1))
            Next
            fgResults.RowSel = 0
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "Display_Results", strSql)
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ' ---------------------------------QUERY FUNCTIONS --------------------------------------------------------'
    Private Function BuildSelectClause() As String
        'Builds Select Clause with fields dbName and as 
        Dim strSelect As String = ""
        Dim intCount As Integer
        Try
            For intCount = 0 To dtDItemsToShow.Rows.Count - 1
                If Trim(strSelect) <> "" Then strSelect = strSelect & ","
                If dtDItemsToShow.Rows(intCount).Item(2) = "DATETIME" Then
                    strSelect = strSelect & GetDateFiled(dtDItemsToShow.Rows(intCount).Item(0)) & " AS '" & dtDItemsToShow.Rows(intCount).Item(1) & "'"
                Else
                    strSelect = strSelect & dtDItemsToShow.Rows(intCount).Item(0) & " AS '" & dtDItemsToShow.Rows(intCount).Item(1) & "'"
                End If
            Next
            Return strSelect
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "BuildSelectClause", strSelect)
            Me.Cursor = Cursors.Default
            Return ""
        End Try
    End Function

    Public Shared Function GetDateFiled(ByVal Fieldname As String) As String
        Dim Final As String = ""
        Dim pattern As String
        Dim sep As String
        Dim patarr() As String
        Dim str As String
        Dim i As Integer
        pattern = BCommon.GetConfigValues("DateDisplayFormat")
        sep = BCommon.GetConfigValues("DateDisplaySeparator")
        patarr = pattern.Split(sep)
        For i = 0 To UBound(patarr)
            str = ""
            Select Case Mid(patarr(i), 1, 1).ToUpper
                Case "M"
                    str = "RTrim(DatePart(mm," & Fieldname & "))"
                Case "Y"
                    str = "RTrim(DatePart(yyyy," & Fieldname & "))"
                Case "D"
                    str = "RTrim(DatePart(dd," & Fieldname & "))"
            End Select
            If Final.Length = 0 Then
                Final = str
            Else
                Final = Final & str
            End If
            If i <> UBound(patarr) Then
                Final = Final & " +'" & sep & "'+ "
            End If
        Next
        Return Final
    End Function

    Private Function FromClause() As String
        'Builds FROM clause from mSearchTable directly
        Try
            Return "FROM " & dtbMsearch.Rows(cmDSearch.SelectedIndex).Item(2).ToString()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "FromClause")
            Me.Cursor = Cursors.Default
            Return ""
        End Try
    End Function

    Private Function OrderClause() As String
        'Builds FROM clause from mSearchTable directly
        Try
            Return dtbMsearch.Rows(cmDSearch.SelectedIndex).Item(4).ToString()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "OrderClause")
            Me.Cursor = Cursors.Default
            Return ""
        End Try
    End Function

    Private Function WhereClause() As String
        'Builds WhereClause with fields whose search criteria is not ALL and values are entered
        Dim strWhere As String = ""
        Dim intCount As Integer
        Dim intlength As Integer
        Try
            strWhere = dtbMsearch.Rows(cmDSearch.SelectedIndex).Item(3).ToString()
            For intCount = 0 To intArraySize - 1
                If txtValue(intCount).Visible = True And (txtValue(intCount).Text) <> "" And Trim(txtValue(intCount).Text) <> "ALL" Then
                    If Trim(strWhere) <> "" Then strWhere = strWhere & " AND "
                    Select Case dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(2)
                        Case "INT"
                            strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " " & txtValue(intCount).Text
                            If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                strWhere = strWhere & " AND  " & txtValueTo(intCount).Text
                            End If
                        Case "DATETIME"

                            strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & BCommon.GetDBDate(txtValue(intCount).Text) & "'"
                            If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                strWhere = strWhere & " AND  '" & BCommon.GetDBDate(txtValueTo(intCount).Text) & "'"
                            End If
                        Case "STRING"
                            If Trim(dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0)) = "LIKE" Then
                                strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "%'"
                            Else
                                strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "'"
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    strWhere = strWhere & " AND  '" & txtValueTo(intCount).Text & "'"
                                End If
                            End If
                        Case "CHAR"
                            If Trim(dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0)) = "LIKE" Then
                                strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "%'"
                            Else
                                strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "'"
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    strWhere = strWhere & " AND  '" & txtValueTo(intCount).Text & "'"
                                End If
                            End If
                        Case "DOUBLE" 'Or "FLOAT"
                            strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " " & txtValue(intCount).Text
                            If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                strWhere = strWhere & " AND  " & txtValueTo(intCount).Text
                            End If
                        Case "IDSTRING"
                            If Trim(dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0)) = "LIKE" Then
                                strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "%'"
                            Else
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    intlength = BCommon.GetSequentialCode(dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(4).ToString).Length
                                    strWhere = strWhere & "SUBSTRING(" & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & "," & CStr(intlength + 1) & ",LEN(" & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & "))"
                                    strWhere = strWhere & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " " & txtValue(intCount).Text.Substring(intlength) & " "
                                    strWhere = strWhere & " AND  " & txtValueTo(intCount).Text.Substring(intlength) & ""
                                Else
                                    strWhere = strWhere & dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(0) & " " & dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) & " '" & txtValue(intCount).Text & "'"
                                End If
                            End If
                    End Select
                End If
            Next
            If strWhere <> "" Then
                Return " WHERE " & strWhere
            Else
                Return ""
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "WhereClause", strWhere)
            Me.Cursor = Cursors.Default
            Return ""
        End Try
    End Function

    ' ---------------------------------Grid Color Settings --------------------------------------------------------'
    Private Sub SetGridColor()
        Try
            'Sets girds color as form color 
            With cfgShowGroup
                '.BackColor = Color.LightSteelBlue
                '.Styles.Normal.BackColor = Color.LightSteelBlue
                '.Styles.Alternate.BackColor = Color.LightSteelBlue
                '.Styles.Fixed.BackColor = Color.LightSteelBlue
                ''.Styles.Focus.BackColor = Color.LightSteelBlue
                '.Styles.Editor.BackColor = Color.LightSteelBlue
                '.Styles.Highlight.BackColor = Color.LightSteelBlue
                '.Styles.EmptyArea.BackColor = Color.LightSteelBlue
                '.Styles.Search.BackColor = Color.LightSteelBlue
                '.Styles.Frozen.BackColor = Color.LightSteelBlue
                '.Styles.NewRow.BackColor = Color.LightSteelBlue

                '.Styles.Normal.Border.Color = Color.LightSteelBlue
                '.Styles.Alternate.Border.Color = Color.LightSteelBlue
                '.Styles.Fixed.Border.Color = Color.LightSteelBlue
                ''.Styles.Focus.Border.Color = Color.LightSteelBlue
                '.Styles.Editor.Border.Color = Color.LightSteelBlue
                '.Styles.Highlight.Border.Color = Color.LightSteelBlue
                '.Styles.EmptyArea.Border.Color = Color.LightSteelBlue
                '.Styles.Search.Border.Color = Color.LightSteelBlue
                '.Styles.Frozen.Border.Color = Color.LightSteelBlue
                '.Styles.NewRow.Border.Color = Color.LightSteelBlue
            End With

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetGridColor")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ' ---------------------------------VALIDATIONS--------------------------------------------------------'
    Private Function ValidateValues() As Boolean
        'Validates Value controls as per there Database
        Dim intCount As Integer
        Dim strCode As String
        Try
            For intCount = 0 To intArraySize - 1
                If txtValue(intCount).Visible = True And Trim(txtValue(intCount).Text) <> "" And Trim(txtValue(intCount).Text) <> "ALL" Or txtValueTo(intCount).Visible = True And Trim(txtValueTo(intCount).Text) <> "" And Trim(txtValueTo(intCount).Text) <> "ALL" Then

                    Select Case dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(2)

                        Case "INT"
                            If BCommon.IsInteger(txtValue(intCount).Text) = False Then
                                txtValue(intCount).Focus()
                                Return False
                                Exit Function
                            Else
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    If BCommon.IsInteger(txtValueTo(intCount).Text) = False Then
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    ElseIf CInt(txtValue(intCount).Text) > CInt(txtValueTo(intCount).Text) Then
                                        BCommon.ShowMsgError(10104)
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    End If
                                End If
                            End If

                        Case "DATETIME"
                            If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                If txtValue(intCount).Text = "" Then
                                    BCommon.ShowMsgError(10322)
                                    txtValue(intCount).Focus()
                                    Return False
                                    Exit Function
                                End If
                                If txtValueTo(intCount).Text = "" Then
                                    BCommon.ShowMsgError(10323)
                                    txtValueTo(intCount).Focus()
                                    Return False
                                    Exit Function

                                End If
                                If CDate(txtValue(intCount).Text) > CDate(txtValueTo(intCount).Text) Then
                                    BCommon.ShowMsgError(10104)
                                    txtValueTo(intCount).Focus()
                                    Return False
                                    Exit Function

                                End If
                            End If

                        Case "CHAR"
                            If BCommon.IsChar(txtValue(intCount).Text) = False Then
                                txtValue(intCount).Focus()
                                Return False
                                Exit Function
                            Else
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    If BCommon.IsChar(txtValueTo(intCount).Text) = False Then
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    ElseIf CChar(txtValue(intCount).Text) > CChar(txtValueTo(intCount).Text) Then
                                        BCommon.ShowMsgError(10104)
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    End If
                                End If
                            End If

                        Case "DOUBLE" 'Or "FLOAT"
                            If BCommon.IsFloat(txtValue(intCount).Text) = False Then
                                txtValue(intCount).Focus()
                                Return False
                                Exit Function
                            Else
                                If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                    If BCommon.IsFloat(txtValueTo(intCount).Text) = False Then
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    ElseIf CDbl(txtValue(intCount).Text) > CDbl(txtValueTo(intCount).Text) Then
                                        BCommon.ShowMsgError(10104)
                                        txtValueTo(intCount).Focus()
                                        Return False
                                        Exit Function
                                    End If
                                End If
                            End If

                        Case "IDSTRING"
                            If dtbOperArr(intCount).Rows(cmbOperArr(intCount).SelectedIndex).Item(0) = "BETWEEN" Then
                                strCode = BCommon.GetSequentialCode(dtDItemArr(intCount).Rows(cmDItemArr(intCount).SelectedIndex).Item(4).ToString)
                                If txtValue(intCount).Text.ToUpper.StartsWith(strCode.ToUpper) = False Then
                                    BCommon.ShowMsgError(10106)
                                    txtValue(intCount).Focus()
                                    Return False
                                    Exit Function
                                End If
                                If BCommon.CheckInteger(txtValue(intCount).Text.Substring(strCode.Length)) = False Then
                                    BCommon.ShowMsgError(10106)
                                    txtValue(intCount).Focus()
                                    Return False
                                    Exit Function
                                End If
                                If txtValueTo(intCount).Text.ToUpper.StartsWith(strCode.ToUpper) = False Then
                                    BCommon.ShowMsgError(10106)
                                    txtValueTo(intCount).Focus()
                                    Return False
                                    Exit Function
                                End If

                                If BCommon.CheckInteger(txtValueTo(intCount).Text.Substring(strCode.Length)) = False Then
                                    BCommon.ShowMsgError(10106)
                                    txtValueTo(intCount).Focus()
                                    Return False
                                    Exit Function
                                End If
                            End If
                    End Select
                End If
            Next
            Return True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ValidateValues")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    ' --------------------------------- HANDLERS --------------------------------------------------------'
    Private Sub AddComboHandlers()
        Dim intCount As Integer
        Try
            For intCount = 0 To intArraySize - 1
                AddHandler cmbOperArr(intCount).SelectedValueChanged, AddressOf cmbOperator_Click
                AddHandler cmDItemArr(intCount).SelectedValueChanged, AddressOf cmDItem_Click
                Debug.Print(intCount)
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddComboHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub AddDateHandlers(ByVal intCount As Integer)
        Try
            AddHandler txtValue(intCount).Click, AddressOf txtForDate_Click
            AddHandler txtValueTo(intCount).Click, AddressOf txtForDate_Click
            AddHandler txtValue(intCount).KeyDown, AddressOf txtForDate_KeyDown
            AddHandler txtValueTo(intCount).KeyDown, AddressOf txtForDate_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddDateHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub AddCharHandlers(ByVal intCount As Integer)
        Try
            AddHandler txtValue(intCount).KeyDown, AddressOf txtCharValue_KeyDown
            AddHandler txtValueTo(intCount).KeyDown, AddressOf txtCharValue_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddCharHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub AddIntHandlers(ByVal intCount As Integer)
        Try
            AddHandler txtValue(intCount).KeyDown, AddressOf txtIntValue_KeyDown
            AddHandler txtValueTo(intCount).KeyDown, AddressOf txtIntValue_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddIntHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub AddDoubleHandlers(ByVal intCount As Integer)
        Try
            AddHandler txtValue(intCount).KeyDown, AddressOf txtDoubleValue_KeyDown
            AddHandler txtValueTo(intCount).KeyDown, AddressOf txtDoubleValue_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddDoubleHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub AddStringHandlers(ByVal intCount As Integer)
        Try
            AddHandler txtValue(intCount).KeyDown, AddressOf txtStringValue_KeyDown
            AddHandler txtValueTo(intCount).KeyDown, AddressOf txtStringValue_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AddStringHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub RemoveAllValueHandlers()
        Dim intCount As Integer
        Try
            For intCount = 0 To intArraySize - 1
                Call RemoveValueHandlers(intCount)
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "RemoveAllValueHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub RemoveValueHandlers(ByVal intCount As Integer)

        Try
            RemoveHandler txtValue(intCount).Click, AddressOf txtForDate_Click
            RemoveHandler txtValueTo(intCount).Click, AddressOf txtForDate_Click

            RemoveHandler txtValue(intCount).KeyDown, AddressOf txtForDate_KeyDown
            RemoveHandler txtValueTo(intCount).KeyDown, AddressOf txtForDate_KeyDown

            RemoveHandler txtValue(intCount).KeyDown, AddressOf txtCharValue_KeyDown
            RemoveHandler txtValueTo(intCount).KeyDown, AddressOf txtCharValue_KeyDown

            RemoveHandler txtValue(intCount).KeyDown, AddressOf txtIntValue_KeyDown
            RemoveHandler txtValueTo(intCount).KeyDown, AddressOf txtIntValue_KeyDown

            RemoveHandler txtValue(intCount).KeyDown, AddressOf txtDoubleValue_KeyDown
            RemoveHandler txtValueTo(intCount).KeyDown, AddressOf txtDoubleValue_KeyDown

            RemoveHandler txtValue(intCount).KeyDown, AddressOf txtStringValue_KeyDown
            RemoveHandler txtValueTo(intCount).KeyDown, AddressOf txtStringValue_KeyDown
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "RemoveValueHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub RemoveComboHandlers()
        Dim intCount As Integer
        Try
            For intCount = 0 To intArraySize - 1
                RemoveHandler cmbOperArr(intCount).SelectedValueChanged, AddressOf cmbOperator_Click
                RemoveHandler cmDItemArr(intCount).SelectedValueChanged, AddressOf cmDItem_Click
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "RemoveComboHandlers")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ' ---------------------------------EVENT HANDLER PROCEDURES --------------------------------------------------------'
    Private Sub cmbOperator_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim intItemIndex As Integer = Array.IndexOf(cmbOperArr, sender).ToString()
            If intItemIndex < 0 Then Me.Cursor = Cursors.Default : Exit Sub
            txtValue(intItemIndex).Text = ""
            txtValueTo(intItemIndex).Text = ""
            Select Case sender.Text

                Case "ALL"
                    txtValue(intItemIndex).Visible = False
                    txtValueTo(intItemIndex).Visible = False
                    lblTo(intItemIndex).Visible = False
                    dtPicker.Visible = False
                Case "FROM"
                    txtValue(intItemIndex).Visible = True
                    txtValueTo(intItemIndex).Visible = True
                    lblTo(intItemIndex).Visible = True
                    dtPicker.Visible = False
                    txtValue(intItemIndex).Focus()

                Case Else
                    txtValue(intItemIndex).Visible = True
                    txtValue(intItemIndex).Focus()
                    txtValueTo(intItemIndex).Visible = False
                    lblTo(intItemIndex).Visible = False
                    dtPicker.Visible = False
            End Select
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cmbOperator_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtForDate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Call onEventShowDTPicker(sender)
    End Sub

    Private Sub txtCharValue_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            If e.KeyCode = 222 Or sender.Text.Length > 1 Then e.SuppressKeyPress = True : Exit Sub 'RemoveLatestEnteredChar(sender) : Exit Sub
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtCharValue_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtIntValue_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            Select Case e.KeyCode
                Case 222
                    e.SuppressKeyPress = True : Exit Sub
                Case Keys.Back, Keys.Delete, Keys.Tab, Keys.Home, Keys.End, Keys.Enter, Keys.Up, Keys.Left, Keys.Right, Keys.Down, Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9
                Case Keys.Decimal, Keys.OemPeriod
                    If sender.Text.IndexOf(".") >= 0 Then e.SuppressKeyPress = True : Exit Sub
                Case Else
                    e.SuppressKeyPress = True : Exit Sub
            End Select
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtIntValue_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtDoubleValue_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            Select Case e.KeyCode
                Case 222
                    e.SuppressKeyPress = True : Exit Sub
                Case Keys.Back, Keys.Delete, Keys.Tab, Keys.Home, Keys.End, Keys.Enter, Keys.Up, Keys.Left, Keys.Right, Keys.Down, Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9
                Case Keys.Decimal, Keys.OemPeriod
                    If sender.Text.IndexOf(".") >= 0 Then e.SuppressKeyPress = True : Exit Sub
                Case Else
                    e.SuppressKeyPress = True : Exit Sub
            End Select
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtDoubleValue_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtStringValue_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            If e.KeyCode = 222 Then e.SuppressKeyPress = True : Exit Sub ' ReplaceSingleQuote(sender) : Exit Sub
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtStringValue_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtForDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Call onEventShowDTPicker(sender)
    End Sub

    Private Sub onEventShowDTPicker(ByRef sender As Object)
        Try
            dtPicker.Parent = grpbControls
            dtPicker.Location = sender.Location
            dtPicker.Width = sender.Width
            dtPicker.Format = DateTimePickerFormat.Custom
            dtPicker.CustomFormat = "dd/MM/yy"
            dtPicker.BringToFront()
            If Trim(sender.Text) <> "" Then dtPicker.Value = BCommon.GetDBDate(sender.Text)
            dtPicker.Visible = True
            dtPicker.Focus()
            dtPicker.TabIndex = sender.TabIndex + 1
            dtPicker.Tag = sender
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "onEventShowDTPicker")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmDItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim intItemIndex As Integer
        Try
            intItemIndex = Array.IndexOf(cmDItemArr, sender).ToString()
            Call RemoveValueHandlers(intItemIndex)
            Select Case dtDItemArr(intItemIndex).Rows.Item(sender.SelectedIndex).Item(2)
                Case "INT"
                    dtbOperArr(intItemIndex) = DSearch.GetAllOperators
                    Call AddIntHandlers(intItemIndex)
                Case "DATETIME"
                    dtbOperArr(intItemIndex) = DSearch.GetAllOperators
                    Call AddDateHandlers(intItemIndex)

                Case "STRING"
                    If dtDItemArr(intItemIndex).Rows.Item(sender.SelectedIndex).Item(3) = "Y" Then
                        dtbOperArr(intItemIndex) = DSearch.GetFromOperators()
                    Else
                        dtbOperArr(intItemIndex) = DSearch.GetOperators
                    End If

                    Call AddStringHandlers(intItemIndex)

                Case "IDSTRING"
                    If dtDItemArr(intItemIndex).Rows.Item(sender.SelectedIndex).Item(3) = "Y" Then
                        dtbOperArr(intItemIndex) = DSearch.GetFromOperators()
                    Else
                        dtbOperArr(intItemIndex) = DSearch.GetOperators
                    End If
                    Call AddStringHandlers(intItemIndex)
                Case "CHAR"
                    dtbOperArr(intItemIndex) = DSearch.GetOperators
                    Call AddCharHandlers(intItemIndex)
                Case "DOUBLE"
                    dtbOperArr(intItemIndex) = DSearch.GetAllOperators
                    Call AddDoubleHandlers(intItemIndex)
            End Select

            cmbOperArr(intItemIndex).DataSource = dtbOperArr(intItemIndex)
            txtValue(intItemIndex).Text = ""
            txtValueTo(intItemIndex).Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cmDItem_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub fgResults_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles fgResults.DoubleClick
        If fgResults.Row > 0 Then btnOk_Click(Nothing, Nothing)
    End Sub

    Private Sub fgResults_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles fgResults.KeyDown
        If e.KeyCode = Keys.Enter And fgResults.Row > 1 Then btnOk_Click(Nothing, Nothing)
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim intCount As Integer
            ClearValueControls()
            HideValueControls()
            fgResults.DataSource = Nothing
            For intCount = 0 To intArraySize - 1
                If cmbOperArr(intCount).Items.Count > 0 Then cmbOperArr(intCount).SelectedIndex = 0
            Next
            For intCount = 0 To dtDItemsToShow.Rows.Count - 1
                cfgShowGroup.Item(intCount + 1, 1) = "True"
            Next
            For intCount = 1 To fgResults.Cols.Count - 1
                fgResults.Cols(intCount).Caption = cfgShowGroup.Rows(intCount).Item(2).ToString
            Next

            'FOR DISPLAY COLUMN
            For intCount = 2 To cfgShowGroup.Rows.Count - 1
                fgResults.Cols(intCount).Visible = CBool(cfgShowGroup.Item(intCount, 1))
            Next
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnCancel_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cfgShowGroup_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cfgShowGroup.GotFocus
        If cfgShowGroup.Row = 1 Then cfgShowGroup.Row = 2
    End Sub

    Private Sub cfgShowGroup_ValidateEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.ValidateEditEventArgs) Handles cfgShowGroup.ValidateEdit
        If e.Row = 2 Then e.Cancel = True
    End Sub

    Public Sub PrintFinalBIll()
        Dim Layoutid As Integer
        Dim PWi As Double
        Dim Ps As PaperSize
        Dim dtGetData As New DataTable

        Try
            Layoutid = BCommon.GetPrefValue("SALEBILLLAYOUT")
            If Layoutid <= 0 Then
                BCommon.ShowMsgError(10338)
                Me.Cursor = Cursors.Default
                Exit Sub
            End If
            dtGetData = DDocument.GetData(Layoutid)
            If dtGetData.Rows.Count > 0 Then
                With PrintDocument1.DefaultPageSettings
                    PHi = (dtGetData.Rows(0).Item("Height") * 100)
                    PWi = (dtGetData.Rows(0).Item("Width") * 100)
                    Ps = New PaperSize("Cust", PWi, PHi)

                    .Margins.Top = (dtGetData.Rows(0).Item("TopM") * 100)
                    .Margins.Bottom = (dtGetData.Rows(0).Item("BottomM") * 100)
                    .Margins.Left = (dtGetData.Rows(0).Item("LeftM") * 100)
                    .Margins.Right = (dtGetData.Rows(0).Item("RightM") * 100)
                    .PaperSize = Ps
                End With
            End If
            headfont = New Font("MS Serif", 12, FontStyle.Bold)
            tableFont = New Font("MS Serif", 8)
            titlefont = New Font("MS Serif", 9)
            tabletitlefont = New Font("MS Serif", 8, FontStyle.Bold)

            X1 = PrintDocument1.DefaultPageSettings.Margins.Left

            With PrintDocument1.DefaultPageSettings
                pageWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
            End With
            X2 = X1 + 120
            X3 = X2 + pageWidth * 0.5

            'COLLECT THE FOOTER LINES 
            Foot1 = BCommon.GetPrefValue("SALEFOOT1")
            Foot2 = BCommon.GetPrefValue("SALEFOOT2")
            Foot3 = BCommon.GetPrefValue("SALEFOOT3")

            If ConfigurationManager.AppSettings("Mode").ToString() = "D" Then
                PrintPreviewDialog1.Document = PrintDocument1
                'Divya @ 14/03/2008
                PrintPreviewDialog1.ShowIcon = True
                'Me.PrintPreviewDialog1.Icon = Global.Pharmacy.My.Resources.RxOffice1Icon32x32
                '>>End
                PrintPreviewDialog1.ShowDialog()
            Else
                PrintDocument1.Print()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ShowCustomerDetails")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
        Dim fmtr As New StringFormat(StringFormatFlags.NoClip)
        Dim fmtalgin As New StringFormat(fmtr)
        Dim TextSize As New System.Drawing.SizeF

        Y = PrintDocument1.DefaultPageSettings.Margins.Top + 10
        curY = PrintDocument1.DefaultPageSettings.Margins.Top + 10

        Dim count As Integer = 0
        Dim intCount As Integer = 1
        Dim curRowHeight As Integer
        Dim FootStart As Integer
        Dim dt As New DataTable
        Dim strCheckFinal As String

        strCheckFinal = BCommon.CheckFinalBill(ClsComman.SaleID)
        'dt = BCommon.GetDocumentBillItems(ClsComman.BillID, ClsComman.SaleID)
        dt = BCommon.GetDocumentBillItems(ClsComman.SaleID, strCheckFinal)

        Try
            Me.Cursor = Cursors.WaitCursor
            Call SetPageHeader(e) 'Setting the Header
            FootStart = PHi - GetFooterHeight(e) - PrintDocument1.DefaultPageSettings.Margins.Bottom

            For intCount = intPrintNext To dt.Rows.Count
                'RESET PageNo to 1 if All Records are displayed.
                If intCount = dt.Rows.Count Then
                    PageNo = 1
                End If
                If IsNothing(dt.Rows(intCount - 1).Item("ItemName")) = False Then
                    'If IsNothing(fgItems.Item(intCount, "ITEMNAME")) = False Then
                    TextSize = e.Graphics.MeasureString(dt.Rows(intCount - 1).Item("ItemName").ToString(), tableFont)
                    curRowHeight = TextSize.Height
                    'DESC  +  COMP  +  EXP  + BATCH + QTY  + AMOUNT 
                    '  8   +    2   +   1.5   +   3   +   2  +   2

                    If FootStart > curY + curRowHeight Then
                        e.Graphics.DrawString(dt.Rows(intCount - 1).Item("ItemName").ToString(), tableFont, Brushes.Black, DrawRectangelF(X1, curY, (wi * 8) - 2, curRowHeight), fmt)
                        'e.Graphics.DrawRectangle(Pens.Black, X1, curY, (wi * 8) - 2, curRowHeight)
                        e.Graphics.DrawString(dt.Rows(intCount - 1).Item("mfctrShortName").ToString(), tableFont, Brushes.Black, DrawRectangelF(X1 + (wi * 8), curY, (wi * 1.5) - 2, curRowHeight), fmt) 'Company Name
                        e.Graphics.DrawString(Format(CDate(dt.Rows(intCount - 1).Item("EXPDATE")), "MM/yy"), tableFont, Brushes.Black, DrawRectangelF(X1 + (wi * 9.5), curY, (wi * 2) - 2, curRowHeight), fmt)
                        e.Graphics.DrawString(Trim(dt.Rows(intCount - 1).Item("CLRcode")), tableFont, Brushes.Black, DrawRectangelF(X1 + (wi * 11.5), curY, (wi * 3) - 2, curRowHeight), fmt)
                        fmtalgin.Alignment = StringAlignment.Far
                        e.Graphics.DrawString(dt.Rows(intCount - 1).Item("Qty").ToString(), tableFont, Brushes.Black, DrawRectangelF(X1 + (wi * 14.5), curY, (wi * 2) - 2, curRowHeight), fmtalgin)
                        e.Graphics.DrawString(BCommon.CheckDecimal(dt.Rows(intCount - 1).Item("Amount").ToString()), tableFont, Brushes.Black, DrawRectangelF(X1 + (wi * 16.5), curY, (wi * 3) - 5, curRowHeight), fmtalgin)
                        If IsNothing(dt.Rows(intCount - 1).Item("Amount")) = False Then
                            dobTotal = dobTotal + Convert.ToDouble(dt.Rows(intCount - 1).Item("Amount").ToString())
                        End If
                        count = (count - 1) + 1
                        curY = curY + curRowHeight
                        e.HasMorePages = False
                        intPrintNext = 1
                    Else
                        e.HasMorePages = True
                        intPrintNext = intCount
                        curY = FootStart
                        Call SetPageFooter(e)   'Setting the Footer When Record goes to Next Page
                        PageNo = PageNo + 1
                        Exit For
                    End If
                Else
                    curY = FootStart
                    Call SetPageFooter(e)      'Setting the Footer When Record Available in One Page
                    Exit For
                End If
            Next
            If e.HasMorePages = False Then
                curY = FootStart
                Call SetPageFooter(e)
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "PrintDocument1_PrintPage")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub SetPageHeader(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim X As Integer
        Dim dtFirm As New DataTable
        Dim TextSize As New System.Drawing.SizeF
        Dim XStart As Integer
        Dim fmtr As New StringFormat(StringFormatFlags.NoClip)
        Dim fmtalign As New StringFormat(fmtr)
        Dim dt As New DataTable
        Dim strCheckFinal As String

        Try
            strCheckFinal = BCommon.CheckFinalBill(ClsComman.SaleID)
            'dt = BCommon.GetCustomerDoct(ClsComman.BillID, ClsComman.SaleID)
            dt = BCommon.GetCustomerDoct(ClsComman.SaleID, strCheckFinal)

            dtFirm = BCommon.FirmInfo()
            With PrintDocument1.DefaultPageSettings
                X = .PaperSize.Width - .Margins.Left - .Margins.Right
            End With

            If PageNo > 1 Then 'For Next Pages in Same Bill Page No print instead of Date
                TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                XStart = X - (TextSize.Width + 10)
            Else
                'HEADER STATIC
                TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                XStart = X - (TextSize.Width + 10)
            End If
            fmtalign.Alignment = StringAlignment.Far
            If dtFirm.Rows.Count > 0 Then
                TextSize = e.Graphics.MeasureString(Trim(dtFirm.Rows(0).Item("FirmName").ToString()), headfont)
                e.Graphics.DrawString(Trim(dtFirm.Rows(0).Item("FirmName").ToString()), headfont, Brushes.Black, DrawRectangelF(X1, curY, XStart, TextSize.Height))
                If PageNo > 1 Then
                    TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                    e.Graphics.DrawString("Page No : " & PageNo, titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height), fmtalign)
                Else
                    TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                    e.Graphics.DrawString("Date:" & Format(Now, "dd/MM/yy"), titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height), fmtalign)
                End If

                'Text Size Set to Height of FirmName.
                TextSize = e.Graphics.MeasureString(Trim(dtFirm.Rows(0).Item("FirmName").ToString()), headfont)
                curY = curY + TextSize.Height

                e.Graphics.DrawString(Trim(dtFirm.Rows(0).Item("addDesc1").ToString()) & "," & Trim(dtFirm.Rows(0).Item("Description").ToString()) & "-" & Trim(dtFirm.Rows(0).Item("PinCode").ToString()) & ", Tel: " & Trim(dtFirm.Rows(0).Item("phone1").ToString()), titlefont, Brushes.Black, X1, curY)
                'e.Graphics.DrawString("Bill No:" & txtVoucher.Text, titlefont, Brushes.Black, DrawRectangelF(XStart, curY, XStart, TextSize.Height))
                TextSize = e.Graphics.MeasureString(Trim(dtFirm.Rows(0).Item("addDesc1").ToString()) & "," & Trim(dtFirm.Rows(0).Item("Description").ToString()) & "-" & Trim(dtFirm.Rows(0).Item("PinCode").ToString()) & ", Tel: " & Trim(dtFirm.Rows(0).Item("phone1").ToString()), titlefont)

                curY = curY + TextSize.Height

            Else  'IF FIRM INFORMATION NOT FOUND
                If PageNo > 1 Then 'Pankaj
                    TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                    e.Graphics.DrawString("", headfont, Brushes.Black, DrawRectangelF(X1, curY, XStart - 10, TextSize.Height))
                    e.Graphics.DrawString("Page No : " & PageNo, titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height), fmtalign)
                Else
                    TextSize = e.Graphics.MeasureString("Date: dd/MM/yy", titlefont)
                    e.Graphics.DrawString("", headfont, Brushes.Black, DrawRectangelF(X1, curY, XStart - 10, TextSize.Height))
                    e.Graphics.DrawString("Date:" & Format(Now, "dd/MM/yy"), titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height), fmtalign)
                End If
                curY = curY + TextSize.Height
            End If

            If PageNo = 1 Then
                If dt.Rows(0).Item("CustomerName") <> "" Then
                    TextSize = e.Graphics.MeasureString("Add : XXXXXX", titlefont)
                    XStart = X - (TextSize.Width + 10)
                    e.Graphics.DrawString("Patient   : " & dt.Rows(0).Item("CustomerName").ToString(), titlefont, Brushes.Black, DrawRectangelF(X1, curY, XStart, TextSize.Height))
                    e.Graphics.DrawString("Add : ", titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height))
                    curY = curY + TextSize.Height
                End If
            End If

            If dt.Rows(0).Item("DoctorName") <> "" Then
                TextSize = e.Graphics.MeasureString("Bill No:" & dt.Rows(0).Item("SEQSALEID"), titlefont)
                XStart = X - (TextSize.Width + 10)
                If PageNo = 1 Then
                    e.Graphics.DrawString("Doctor : " & dt.Rows(0).Item("DoctorName").ToString(), titlefont, Brushes.Black, DrawRectangelF(X1, curY, XStart, TextSize.Height))
                Else
                    e.Graphics.DrawString("", titlefont, Brushes.Black, DrawRectangelF(X1, curY, XStart, TextSize.Height))
                End If
                e.Graphics.DrawString("Bill No: " & dt.Rows(0).Item("SEQSALEID"), titlefont, Brushes.Black, DrawRectangelF(XStart + X1, curY, TextSize.Width + 10, TextSize.Height), fmtalign)
                TextSize = e.Graphics.MeasureString("Doctor : " & dt.Rows(0).Item("DoctorName").ToString(), titlefont)
                curY = curY + TextSize.Height
            End If

            With PrintDocument1.DefaultPageSettings
                e.Graphics.DrawLine(Pens.Black, .Margins.Left, curY, .PaperSize.Width - .Margins.Right, curY)
                wi = X / 20
            End With

            'DESC  +  COMP  +  EXP  + BATCH + QTY  + AMOUNT 
            '  8   +    2   +   1.5   +   3   +   2  +   2
            'Caption of the Print Bill
            '=========================

            e.Graphics.DrawString("Description", tabletitlefont, Brushes.Black, X1, curY)
            e.Graphics.DrawString("Comp", tabletitlefont, Brushes.Black, X1 + (wi * 8), curY)
            e.Graphics.DrawString("Exp", tabletitlefont, Brushes.Black, X1 + (wi * 9.5), curY)
            e.Graphics.DrawString("CLRcode", tabletitlefont, Brushes.Black, X1 + (wi * 11.5), curY)
            e.Graphics.DrawString("Qty", tabletitlefont, Brushes.Black, X1 + (wi * 16), curY)
            e.Graphics.DrawString("Amount", tabletitlefont, Brushes.Black, X1 + (wi * 18), curY)
            TextSize = e.Graphics.MeasureString("Description", tabletitlefont)
            curY = curY + TextSize.Height
            With PrintDocument1.DefaultPageSettings
                e.Graphics.DrawLine(Pens.Black, .Margins.Left, curY, .PaperSize.Width - .Margins.Right, curY)
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetPageHeader")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub SetPageFooter(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim TextSize As New System.Drawing.SizeF
        Dim FooterRowHieght As Integer
        Dim XStart As Integer
        Dim PWidth As Integer ' Page Width 
        Dim tempstr As String
        Dim dt As New DataTable
        Dim strCheckFinal As String

        Try
            If e.HasMorePages = False Then
                TextSize = e.Graphics.MeasureString("Pharmacist", titlefont)
            Else
                TextSize = e.Graphics.MeasureString("...Cotinued", titlefont)
            End If

            FooterRowHieght = TextSize.Height

            strCheckFinal = BCommon.CheckFinalBill(ClsComman.SaleID)

            'dt = BCommon.GetCustomerDoct(ClsComman.BillID, ClsComman.SaleID)
            dt = BCommon.GetCustomerDoct(ClsComman.SaleID, strCheckFinal)
            With PrintDocument1.DefaultPageSettings
                e.Graphics.DrawLine(Pens.Black, .Margins.Left, curY, .PaperSize.Width - .Margins.Right, curY)
                PWidth = .PaperSize.Width - .Margins.Right
            End With

            If e.HasMorePages = False Then
                TextSize = e.Graphics.MeasureString("Net Amt : " & ConfigurationManager.AppSettings("Currency") & " " & dt.Rows(0).Item("GrossAmount").ToString(), titlefont)
                XStart = PWidth - (TextSize.Width + 10)
                e.Graphics.DrawString("Total :" & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(dobTotal.ToString()), titlefont, Brushes.Black, X1, curY)
                If dt.Rows(0).Item("Discount").ToString() <> "" Then
                    e.Graphics.DrawString("Disc : " & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(Math.Round(CDbl(dt.Rows(0).Item("Discount").ToString()), 2).ToString()), titlefont, Brushes.Black, (XStart / 2), curY)
                End If
                e.Graphics.DrawString("Net Amt : " & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(dt.Rows(0).Item("GrossAmount").ToString()), titlefont, Brushes.Black, XStart, curY)
                curY = curY + FooterRowHieght

                If dt.Rows(0).Item("Discount").ToString() <> "" Then
                    e.Graphics.DrawString("Paid : " & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(Math.Round(CDbl(dt.Rows(0).Item("PaidAmount").ToString()), 2).ToString()), titlefont, Brushes.Black, (XStart / 2), curY)
                End If

                Dim BalAmt As Double = 0.0
                BalAmt = Math.Round(CDbl(dt.Rows(0).Item("GrossAmount")), 2) - Math.Round(CDbl(dt.Rows(0).Item("PaidAmount")), 2)

                TextSize = e.Graphics.MeasureString("Bal Amt : " & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(BalAmt.ToString), titlefont)
                XStart = PWidth - (TextSize.Width + 10)

                e.Graphics.DrawString("Bal Amt : " & ConfigurationManager.AppSettings("Currency") & " " & BCommon.CheckDecimal(BalAmt.ToString), titlefont, Brushes.Black, XStart, curY)
                curY = curY + FooterRowHieght
                dobTotal = 0.0 'ReSet dobTotal to 0 because it is globaly defined.
            End If

            With PrintDocument1.DefaultPageSettings
                e.Graphics.DrawLine(Pens.Black, .Margins.Left, curY, .PaperSize.Width - .Margins.Right, curY)
            End With
            If e.HasMorePages = False Then
                '*********FOOTER SECTION
                'FOOTER LINE 1
                tempstr = "For " & BCommon.GetFirmFullName
                TextSize = e.Graphics.MeasureString(tempstr, titlefont)
                XStart = PWidth - (TextSize.Width + 10)
                e.Graphics.DrawString(Foot1, titlefont, Brushes.Black, DrawRectangelF(X1, curY, XStart - 10, FooterRowHieght))
                e.Graphics.DrawString(tempstr, titlefont, Brushes.Black, DrawRectangelF(XStart, curY, TextSize.Width, FooterRowHieght))
                curY = curY + FooterRowHieght
                'FOOTER LINE 2
                e.Graphics.DrawString(Foot2, titlefont, Brushes.Black, X1, curY)
                curY = curY + FooterRowHieght
                'FOOTER LINE 3
                tempstr = "Pharmacist"
                TextSize = e.Graphics.MeasureString(tempstr, titlefont)
                XStart = PWidth - (TextSize.Width + 10)
                e.Graphics.DrawString(Foot3, titlefont, Brushes.Black, DrawRectangelF(X1, curY, XStart - 10, FooterRowHieght))
                e.Graphics.DrawString(tempstr, titlefont, Brushes.Black, DrawRectangelF(XStart, curY, XStart, FooterRowHieght))
            Else
                TextSize = e.Graphics.MeasureString("...Continued", titlefont)
                XStart = PWidth - (TextSize.Width + 10)
                curY = curY + TextSize.Height
                e.Graphics.DrawString("...Cotinued", titlefont, Brushes.Black, DrawRectangelF(XStart, curY, TextSize.Width, FooterRowHieght))
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetPageFooter")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Function DrawRectangelF(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As RectangleF
        Try
            Dim drawRect As New RectangleF(x, y, width, height)
            Return drawRect
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "DrawRectangelF")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    Private Function GetFooterHeight(ByVal e As System.Drawing.Printing.PrintPageEventArgs) As Integer
        Dim TextSize As New System.Drawing.SizeF
        Dim TotFooterHieght As Integer
        If e.HasMorePages = False Then
            TextSize = e.Graphics.MeasureString("Pharmacist", titlefont)
            '3 Footer Line And One Total Amount Line 
            TotFooterHieght = TextSize.Height * 5
        Else
            TextSize = e.Graphics.MeasureString("...Cotinued", titlefont)
            '3 Footer Line And One Total Amount Line 
            TotFooterHieght = TextSize.Height * 5
        End If
        Return TotFooterHieght
    End Function
End Class

'Private Sub ReplaceSingleQuote(ByRef Sender As Object)
'    Dim pos As Integer
'    Try
'        pos = Sender.SelectionStart - 1
'        Sender.Text = Sender.Text.ToString().Replace("'", "")
'        If pos >= 0 Then Sender.SelectionStart = pos

'    Catch ex As Exception
'        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ReplaceSingleQuote")
'    End Try

'End Sub

'Private Sub RemoveLatestEnteredChar(ByRef Sender As Object)
'    Dim pos As Integer
'    Try
'        pos = Sender.SelectionStart - 1
'        If pos >= 0 Then Sender.Text = Sender.Text.ToString().Remove(pos, 1) : Sender.SelectionStart = pos

'    Catch ex As Exception
'        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "RemoveLatestEnteredChar")
'    End Try
'End Sub
'Private Sub ReplaceChars(ByRef Sender As Object)
'    Dim pos As Integer

'    Try
'        pos = Sender.SelectionStart - 1
'        If pos >= 0 Then Sender.Text = Sender.Text.ToString().Remove(pos, 1) : Sender.SelectionStart = pos

'    Catch ex As Exception
'        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ReplaceChars")
'    End Try

'End Sub
''Divya 22/11/2007
'Private Sub SetDatepickerMaxMinDate()
'    Dim dtDatePkr As DataTable
'    Try
'        dtDatePkr = BCommon.GetDatePicker()
'        If dtDatePkr.Rows.Count > 0 Then
'            dtPicker.MinDate = dtDatePkr.Rows(0).Item("fin_start_dt")
'            dtPicker.MaxDate = dtDatePkr.Rows(0).Item("fin_end_dt")
'        End If
'    Catch ex As Exception
'        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnOk_Click")
'    End Try
'End Sub